/**
 * @description 路由鉴权
 * @author xfj
 */

import { useEffect } from 'react'
import { Outlet, useNavigate, useLocation } from 'react-router-dom'
import useLoginInfo from '../../hooks/useLoginInfo'
import useCurrentRoute from '../../hooks/useCurrentRoute'

export default function AuthRoute() {
  const { auth } = useCurrentRoute()  
  const userInfo = useLoginInfo()  
  const location = useLocation()  
  const navigate = useNavigate()
  
  useEffect(() => {
    if(auth && !userInfo) {
      navigate(`/login?go=${location.pathname}`)
    }
  }, [auth, location.pathname])
  return <Outlet />
}
